package com.mtsmda.is.admin.domain;

import static com.mtsmda.is.admin.domain.util.db.ConstantsDB.*;

public class Attribute {

	private Integer attrId;
	private String attrName;
	private String attrDescription;

	public Attribute() {
		super();
	}

	public Attribute(String attrName, String attrDescription) {
		this();
		setAttrName(attrName);
		setAttrDescription(attrDescription);
	}

	public Integer getAttrId() {
		return attrId;
	}

	public void setAttrId(Integer attrId) {
		this.attrId = attrId;
	}

	public String getAttrName() {
		return attrName;
	}

	public void setAttrName(String attrName) {
		if (attrName.length() > LENGTH_FIELD_250) {
			this.attrName = attrName.substring(0, LENGTH_FIELD_250);
		} else {
			this.attrName = attrName;
		}
	}

	public String getAttrDescription() {
		return attrDescription;
	}

	public void setAttrDescription(String attrDescription) {
		if (attrDescription.length() > LENGTH_FIELD_500) {
			this.attrDescription = attrDescription.substring(0,
					LENGTH_FIELD_500);
		} else {
			this.attrDescription = attrDescription;
		}
	}

	@Override
	public String toString() {
		return "Attribute [attrId=" + attrId + ", attrName=" + attrName
				+ ", attrDescription=" + attrDescription + "]";
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Attribute && obj != null) {
			Attribute attribute = (Attribute) obj;
			if (attribute.getAttrId().equals(this.getAttrId())
					&& attribute.getAttrName().equals(this.getAttrName())
					&& attribute.getAttrDescription().equals(
							getAttrDescription())) {
				return true;
			}
			if (attribute == this) {
				return true;
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		int hashCode = this.getAttrId().hashCode();
		hashCode += this.getAttrName().hashCode() * 2;
		hashCode += this.getAttrDescription().hashCode() * 31;
		return hashCode;
	}
}